repo.or.cz
/
andmenj-acm.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
Solving 10385 - Duathlon (Ternary search)
[andmenj-acm.git]
/
305 - Joseph
/
2robado305.cpp
blob
0ca039cbb2a65a04fcc0b05a38c938255860d1b1
1
/* Código robado del foro DESPUÉS de haberlo resuelto yo.
2
3
http://acm.uva.es/board/viewtopic.php?t=8570
4
5
*/
6
7
8
9
#include <iostream>
10
using namespace
std
;
11
12
int
f
(
int
k
)
13
{
14
int
m
,
n
,
p
,
r
;
15
16
for
(
n
=
2
*
k
,
m
=
2
;;
m
++) {
17
for
(
p
=
0
,
r
=
n
;
r
>
k
;
r
--)
18
if
((
p
= (
p
+
m
-
1
) %
r
) <
k
)
break
;
19
if
(
r
==
k
)
return
m
;
20
}
21
}
22
23
int
main
(
void
)
24
{
25
int
k
;
26
while
((
cin
>>
k
)&&
k
)
27
cout
<<
f
(
k
) <<
endl
;
28
return
0
;
29
}